#include <zenopy/UsdAPI.hpp>
#include <zenopy/UsdPrim.hpp>
#include <zenox/subroutine.hpp>
#include <zenox/minilog.hpp>
#include <zenopy/PythonClient.hpp>
#include <zenox/glm.hpp>

namespace zenopy {

ZENO_SUBPROGRAM(usd_client_test)(int argc, char **argv) {
    (void)argc;
    (void)argv;

    PythonClient cli;
    cli.open("/tmp/zenopy-socket");

    std::string stageFile = "/home/bate/Downloads/Kitchen_set/Kitchen_set.usd";
    zenox::log_critical("stagePrims: [{}]", zenox::join(stagePrimList(cli, stageFile), ", "));
    std::string primPath = "/Kitchen_set/Props_grp/West_grp/Ball_1/Geom/Ball";
    zenox::log_critical("primProps: [{}]", zenox::join(stagePrimPropNames(cli, stageFile, primPath), ", "));
    std::string propName = "faceVertexIndices";
    zenox::log_critical("propType: {}", stagePrimPropType(cli, stageFile, primPath, propName));
    std::vector<int> out;
    auto shape = stagePrimPropValArray(cli, stageFile, primPath, propName, out, -1);
    zenox::log_critical("propValArray: [{}]", zenox::join(out, ", "));
    zenox::log_critical("propValShape: [{}]", zenox::join(shape, ", "));

    std::vector<int> faceVertexIndices;
    stagePrimPropValArray(cli, stageFile, primPath, "faceVertexIndices", faceVertexIndices);
    std::vector<int> faceVertexCounts;
    stagePrimPropValArray(cli, stageFile, primPath, "faceVertexCounts", faceVertexCounts);
    std::vector<glm::vec3> points;
    stagePrimPropValArray(cli, stageFile, primPath, "points", points);

    return 0;
}

ZENO_SUBPROGRAM(usd_client)(int argc, char **argv) {
    (void)argc;
    (void)argv;

    PythonClient cli;
    cli.open("/tmp/zenopy-socket");

    /* std::string stageFile = "/home/bate/Downloads/Kitchen_set/Kitchen_set.usd"; */
    /* std::string primPath = "/Kitchen_set/Props_grp/West_grp/Ball_1/Geom"; */
    /* zenox::log_warn("{}", stagePrimType(cli, stageFile, primPath)); */
    /* zenox::log_warn("{}", fmt::join(stagePrimPropertyNames(cli, stageFile, primPath), ", ")); */
    /* zenox::log_warn("{}", stagePrimPropType(cli, stageFile, primPath, "xformOpOrder")); */
    /* zenox::log_warn("{}", fmt::join(stagePrimPropValStrList(cli, stageFile, primPath, "xformOpOrder"), ", ")); */

    zenox::log_critical("starts bleeding");
    std::string stageFile = "/home/bate/Downloads/Kitchen_set/Kitchen_set.usd";
    auto stage = usdLoadStage(cli, stageFile);
    zenox::log_critical("end bleeding");

    return 0;
}

}
